package main


func longestPalindrome(s string) string {
    start, end := 0, 0
    for i, _ := range s {
        l1, r1 := expand(s, i, i)
        l2, r2 := expand(s, i, i+1)
        if r1 - l1 > end - start {
            start, end = l1, r1
        }
        if r2 - l2 > end - start {
            start, end = l2, r2
        }
    }
    return s[start:end+1]
}

func expand(s string, l int, r int) (int, int) {
    for l>=0 && r < len(s) && s[l]==s[r] {
        l -= 1
        r += 1
    }
    return l+1, r-1
}
